import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'
import { denglfun } from '../utils/api'

import "./Login.scss"

class Login extends Component {
    constructor(props) {
        super(props)
        this.state={
            phone:'',
            pass:''
        }
    }
    fun = () => {
        this.props.history.push("/zhuce")
    }
    fundl=()=>{
        denglfun({phone:this.state.phone,pass:this.state.pass}).then((ok)=>{
            console.log(ok.data)
        })
        alert("登录成功,确认跳转首页")
        setTimeout(() => {
            this.props.history.push("/routertwo/dianpu")
        }, 3000);
    }
    change=(e)=>{
        this.setState({
           [e.target.name]:(e.target.value)
        },()=>{
           console.log(this.state)
        })
   }
    render() {
        return (
            <div className='background' >
                <input className='text' name='phone' type="text" value={this.state.phone} onChange={(e)=>{this.change(e)}} placeholder='请输入用户名' />
                <input className='password' name='pass' type="password" value={this.state.pass} onChange={(e)=>{this.change(e)}} placeholder='请输入密码' />
                <button onClick={this.fundl}>登录</button>
                <button onClick={this.fun}>注册</button>
            </div>
        )
    }
}
export default withRouter(Login)